package com.rms.server.Controller;

import com.rms.server.Domain.Dish;
import com.rms.server.Service.DishService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/dishes")
@Tag(name = "菜品管理", description = "菜品管理相关接口") // 为接口分组并添加描述
public class DishController {

    @Autowired
    private DishService dishService;

    @PostMapping
    @Operation(summary = "创建菜品", description = "新增一个菜品")
    public String createDish(@RequestBody Dish dish) {
        int result = dishService.addDish(dish);
        return result > 0 ? "Dish added successfully!" : "Failed to add dish.";
    }

    @DeleteMapping("/{dishId}")
    @Operation(summary = "删除菜品", description = "根据 ID 删除指定菜品")
    public String deleteDish(@PathVariable Long dishId) {
        int result = dishService.removeDish(dishId);
        return result > 0 ? "Dish deleted successfully!" : "Failed to delete dish.";
    }

    @PutMapping
    @Operation(summary = "更新菜品", description = "根据传入的菜品对象更新菜品信息")
    public String updateDish(@RequestBody Dish dish) {
        int result = dishService.modifyDish(dish);
        return result > 0 ? "Dish updated successfully!" : "Failed to update dish.";
    }

    @GetMapping("/{dishId}")
    @Operation(summary = "查询单个菜品", description = "根据 ID 查询菜品详情")
    public Dish getDish(@PathVariable Long dishId) {
        return dishService.getDishById(dishId);
    }

    @GetMapping
    @Operation(summary = "查询所有菜品", description = "获取所有菜品的列表信息")
    public List<Dish> getAllDishes() {
        return dishService.getAllDishes();
    }
    @GetMapping("/today")
    @Operation(summary = "今日菜品", description = "随机返回8个菜品")
    public List<Dish> getTodayDishes() {
        return dishService.getRandomDishes();
    }
}
